function findKthToTail(head,k){
    if(head == null || k <= 0){
        return null;
    }
    let preA = head;
    let preB = head;
    // 截取长度
    for(let i = 1; i<k;i++){
        if(preA.next != null){
            preA = preA.next
        }else {
            return null;// k 大于链表长度
        }
    }
    // preA 现在代表的是k后还有多少
    // 这样preB 是从头开始 就是倒数k 秒啊

    while(preA){
        preA = preA.next;
        preB = preB.next;
    }
    return  preB;
}

function ListNode(val) {
    this.name = val;
    this.next = null;
}

var a = new ListNode(1);
var b = new ListNode(2);
var c = new ListNode(3);
// var d = new ListNode(4);
a.next = b;
b.next = c;
// c.next = d

// a -> b -> c -> d -> null

console.log(findKthToTail(a, 3))